package com.itheima.web.controller.sms;


import com.itheima.result.PageResult;
import com.itheima.result.ResultData;
import com.itheima.service.sms.SmsFlashPromotionService;
import com.itheima.vo.sms.SmsFlashPromotion;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

/**
 * 活动接口
 */
@RestController
@RequestMapping("flash")
@Slf4j
public class SmsFlashPromotionController {
    @DubboReference
    private SmsFlashPromotionService smsFlashPromotionService;

    /**
     * 添加活动
     * @param smsFlashPromotion
     * @return
     */
    @PostMapping("create")
    public ResultData create(@RequestBody SmsFlashPromotion smsFlashPromotion){
        log.info("添加的活动信息：{}",smsFlashPromotion);
        int result=smsFlashPromotionService.create(smsFlashPromotion);
        return ResultData.ok("操作成功",result);
    }

    /**
     * 删除活动
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    public ResultData delete(@PathVariable Long id){
        log.info("删除的活动id：{}",id);
        int result=smsFlashPromotionService.delete(id);
        return ResultData.ok("操作成功",result);
    }

    /**
     * 根据活动名称分页查询
     * @param keyword
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("list")
    public ResultData list(String keyword,Integer pageNum,Integer pageSize){
        log.info("分页条件查询条件：{},{},{}",keyword,pageNum,pageSize);
        PageResult pageResult=smsFlashPromotionService.selectPage(keyword,pageNum,pageSize);
        return ResultData.ok("操作成功",pageResult);
    }

    /**
     * 修改上下线状态
     * @param id
     * @param smsFlashPromotion
     * @return
     */
    @PostMapping ("/update/status/{id}")
    public ResultData updateStatus(@PathVariable("id") Long id,SmsFlashPromotion smsFlashPromotion){
        log.info("修改上下线状态:{},{}",id,smsFlashPromotion);
        int result=smsFlashPromotionService.updateStatus(id,smsFlashPromotion);
        return ResultData.ok("操作成功",result);
    }

    /**
     * 编辑活动
     * @param id
     * @param smsFlashPromotion
     * @return
     */
    @PostMapping("update/{id}")
    public ResultData updateFlashPromotion(@PathVariable Long id,@RequestBody SmsFlashPromotion smsFlashPromotion){
        log.info("修改上下线状态:{},{}",id,smsFlashPromotion);
        int result=smsFlashPromotionService.updateFlashPromotion(id,smsFlashPromotion);
        return ResultData.ok("操作成功",result);
    }

    /**
     * 获取活动详情
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public ResultData selectById(@PathVariable Long id){
        log.info("查询活动详情的id：{}",id);
        SmsFlashPromotion smsFlashPromotion=smsFlashPromotionService.selectById(id);
        return ResultData.ok("操作成功",smsFlashPromotion);
    }
}
